package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserIdInvoice;
import com.ruoyi.system.service.IUserIdInvoiceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户发票存根Controller
 * 
 * @author 格格本奈
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/system/userinvoice")
public class UserIdInvoiceController extends BaseController
{
    @Autowired
    private IUserIdInvoiceService userIdInvoiceService;

    /**
     * 查询用户发票存根列表
     */
    @PreAuthorize("@ss.hasPermi('system:userinvoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserIdInvoice userIdInvoice)
    {
        startPage();
        List<UserIdInvoice> list = userIdInvoiceService.selectUserIdInvoiceList(userIdInvoice);
        return getDataTable(list);
    }

    /**
     * 导出用户发票存根列表
     */
    @PreAuthorize("@ss.hasPermi('system:userinvoice:export')")
    @Log(title = "用户发票存根", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserIdInvoice userIdInvoice)
    {
        List<UserIdInvoice> list = userIdInvoiceService.selectUserIdInvoiceList(userIdInvoice);
        ExcelUtil<UserIdInvoice> util = new ExcelUtil<UserIdInvoice>(UserIdInvoice.class);
        util.exportExcel(response, list, "用户发票存根数据");
    }

    /**
     * 获取用户发票存根详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:userinvoice:query')")
    @GetMapping(value = "/{uuid}")
    public AjaxResult getInfo(@PathVariable("uuid") Long uuid)
    {
        return success(userIdInvoiceService.selectUserIdInvoiceByUuid(uuid));
    }

    /**
     * 新增用户发票存根
     */
    @PreAuthorize("@ss.hasPermi('system:userinvoice:add')")
    @Log(title = "用户发票存根", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserIdInvoice userIdInvoice)
    {
        return toAjax(userIdInvoiceService.insertUserIdInvoice(userIdInvoice));
    }

    /**
     * 修改用户发票存根
     */
    @PreAuthorize("@ss.hasPermi('system:userinvoice:edit')")
    @Log(title = "用户发票存根", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserIdInvoice userIdInvoice)
    {
        return toAjax(userIdInvoiceService.updateUserIdInvoice(userIdInvoice));
    }

    /**
     * 删除用户发票存根
     */
    @PreAuthorize("@ss.hasPermi('system:userinvoice:remove')")
    @Log(title = "用户发票存根", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uuids}")
    public AjaxResult remove(@PathVariable Long[] uuids)
    {
        return toAjax(userIdInvoiceService.deleteUserIdInvoiceByUuids(uuids));
    }
}
